﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using hExcel = Microsoft.Office.Interop.Excel;

namespace excel004
{
    class Program
    {
        static void Main(string[] args)
        {
            //open specified excel
            string xls_path = "c:\\Paid_Unpaid.xls";
            hExcel.Application xlsApp = new hExcel.ApplicationClass();
            hExcel.Workbook xlsWorkbook = xlsApp.Workbooks.Open(
                    xls_path,   //file name
                    0,          //UpdateLinks
                    true,       //read-only
                    5,          //Format
                    "",         //password
                    "",         //write password,
                    true,       //IgnoreReadyOnblyReconnected
                    Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, //Origin
                    "\t",       //Delimiter
                    false,      //Editable
                    false,      //Notify
                    0,          //Converter
                    true,       //AddToMru,
                    1,          //Local
                    0           //CorruptLoad
                );
            Console.Write("[OK] Open Excel file\n");
            // get worksheet 1
            hExcel.Worksheet xlsWorksheet = (hExcel.Worksheet)xlsWorkbook.Worksheets.get_Item(1);
          
            // Output Worksheet properties
            hExcel.Range xlsRange = xlsWorksheet.UsedRange;
            int columns = xlsRange.Columns.Count;
            int rows = xlsRange.Cells.Rows.Count;
            Console.Write("[info]Worksheet columns: "+columns+"\n");
            Console.Write("[info]worksheet rows: " + rows + "\n");

            // Find Keyword: Currency
            //(1)set range
            object o2 = columns;
            hExcel.Range h;
           // hExcel.Range titleRange = (hExcel.Range)xlsWorksheet.Columns.get_Item(1, o2);
            hExcel.Range titleRange = xlsWorksheet.get_Range("A1","A"+rows);

            foreach(object element in titleRange.Value2)
            {


            }

            Console.ReadLine();
        }
    }

}
